package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	filenames := make(map[string]int)
	files := os.Args[1:]
	if len(files) == 0 {
		countLines2(os.Stdin, filenames)
	} else {
		for _, arg := range files {
			f, err := os.Open(arg)
			if err != nil {
				fmt.Fprintf(os.Stderr, "dup2: %v\n", err)
				continue
			}
			countLines2(f, filenames)
			f.Close()
		}
	}
	for filename, _ := range filenames {
		fmt.Printf("%s\n", filename)
	}

}

func countLines2(f *os.File, filenames map[string]int) {
	counts := make(map[string]int)
	input := bufio.NewScanner(f)
	for input.Scan() {
		counts[input.Text()]++
		if counts[input.Text()] > 1 {
			path := strings.Split(f.Name(), "/")
			filenames[path[len(path)-1]] = 1
		}
	}
}
